package com.live.dengdengtv;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by wyf on 2016/8/17.
 */
public abstract class CustomTitleActivity extends BaseActivity{

    protected TextView title_center_tv;
    protected TextView title_right_tv;
    protected ImageView title_left_iv;

    public void setContentView(@LayoutRes int layoutResID,@LayoutRes int titleResID) {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        super.setContentView(layoutResID);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,titleResID); // titlebar为自己标题栏的布局
        findView();
    }

    protected void findView(){
        title_center_tv = (TextView) findViewById(R.id.title_center_tv);
        title_right_tv = (TextView) findViewById(R.id.title_right_tv);
        title_left_iv = (ImageView) findViewById(R.id.title_left_iv);



        if(title_left_iv != null){
            title_left_iv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onLeftImageViewClick(v);
                }
            });
        }
        if(title_right_tv != null){
            title_right_tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onRightTextViewClick(v);
                }
            });
        }
    };

    protected void setDefaultTitle(CharSequence title){
        if(title_center_tv != null){

            title_center_tv.setText(title);
            setRightText("");
        }
    }

    protected void setRightText(CharSequence rightText){
        if(title_right_tv != null){
            title_right_tv.setText(rightText);
        }
    }

    protected void onRightTextViewClick(View v){

    }
    protected void onLeftImageViewClick(View v){
        finish();
    }



    public void setBlueTitleView(@LayoutRes int layoutResID) {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        super.setContentView(layoutResID);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title_base_blue);
    }
    public void setRedTitleView(@LayoutRes int layoutResID) {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        super.setContentView(layoutResID);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title_base_red);
    }
}
